<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_SESSION['forward_url']='jy_park_yuyue/home/';
cfc('core')->checklogin();
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
$return['diy']=$this->plugin_setting('diy');
$return['basic']=$this->plugin_setting('basic');
$return['vip']=$this->plugin_setting('vip');
if($_RQ['op']=='main'){
    $member=pdo_get('core_members',array('id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),array('credit1','credit2','mobile','groupid','avatar','nickname'));
	if(!$member){
		exi('找不到会员信息！','error');
	}
	$user_id=pdo_getcolumn('jy_yuyue_user',array('id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),'id');
	$user=pdo_get('jy_yuyue_user',array('id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	if(!$user_id){
		$insert=array(
			'id'=>$_SESSION['uid'],
			'uniacid'=>$_SESSION['uniacid'],
			'mobile'=>$member['mobile'],
			'name'=>$member['nickname'],
			'headimg'=>$member['avatar'],
			'sex'=>$member['sex'],
			'createtime'=>TIMESTAMP,
		);
		pdo_insert('jy_yuyue_user',$insert);
	}else{
		if(empty($user['headimg'])){
			pdo_update('jy_yuyue_user', array('headimg' => $member['avatar'],'name'=>$member['nickname']), array('id' => $_SESSION['uid']));
		}
	}
	$return['member']=$member;
	//VIP时间：
	$user['vipstatus']=$user['viptime']>time()?1:2;
	$user['viptime']=date('Y/m/d',$user['viptime']);
	$return['user']=$user;
	$return['item']=array();
	$return['workerid']=pdo_getcolumn('jy_yuyue_worker',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),'id');
	exi($return);
}
//修改用户信息
if($_RQ['op']=='set'){
	if($_RQ['postdata']){
		$postdata=get_postdata();
		$data=array(
				'name'=>$postdata['name'],
				'mobile'=>$postdata['mobile'],
				'headimg'=>$postdata['headimg'],
				'address'=>$postdata['address'],
				);
		$user_id=pdo_getcolumn('jy_yuyue_user',array('id'=>$_SESSION['uid']),'id');		
		if($user_id){
			pdo_update('jy_yuyue_user',$data,array('id'=>$_SESSION['uid']));
			exi('修改成功','','jy_yuyue/home/');		 
		}
	}
	$user=pdo_get('jy_yuyue_user',array('id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	$member=pdo_get('core_members',array('id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),array('nickname','avatar','mobile'));
	$return['item']=$user;
	$return['member']=$member;
	exi($return);
	}

